<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>项目还款</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
        	<div class="FXBR">
        		<div class="fieldBox">
	                <div class="label">项目名称</div>
	                <div class="field">
	                    <input name="prjNm" id="prjNm"  type="text" class="ui-textbox"   ligerui="width: 160">
	                </div>
	            </div>
        		<div class="fieldBox">
	                <div class="label">融资机构名称</div>
	                <div class="field">
	                    <input name="fncInsId" id="fncInsId" type="text" class="ui-textbox" value="" ligerui="width: 160">
	                </div>
	            </div>
	            <div class="fieldBox">
	                <div class="label">还款类别</div>
	                <div class="field">
	                    <select name="rePyTpCd" id="rePyTpCd" ligerui="width: 160">
	                        <option value="" seleted>请选择</option>
	                        <c:forEach items="${rePyTpCdLst}" var="rePyTpCd">
	                        	<option value="${rePyTpCd.key }">${rePyTpCd.value }</option>
	                        </c:forEach>
	                    </select>
	                </div>
	            </div>
            </div>
            
            <div class="clearFix"></div>
	            <div class="btnsBox formBtns notRight">
	               <span id="searchBtn" class="sq-button-round">查询</span>
	               <span id="clearBtn" class="sq-button-round">清空</span>
	               <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
	            </div>
        	</div>
        </form>
    </div>
</div>
<div id="ligergrid1" class="sq-grid">
</div>

<script type="text/javascript">
	var grid = null;
	$("#clearBtn").click(function(event) {
	    $("#resetBtn").click();  //重置 input-text
	    var form = liger.get("searchBar");
	    form.setData({  //重置select等特殊表单
	        "rePyTpCd": "",
	        "fncInsId": ""
	    });
	});
	$(function () {
		initInstLstForm();
		initGrid();
	    initForm();
		initEvent();
	});
	function initForm(){
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    grid.options.isSingleCheck=true;	
		$("#searchBar").ligerForm();
	}
	
	function initEvent(){
	    $("#searchBtn").click(function(event) {
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         console.log(JSON.stringify(data));
	         for (var name in data){
	            grid.setParm(name,data[name]);
	         };
	        grid.reload();
	    });
	}
	
	function initGrid(){
		$("#ligergrid1").ligerGrid({
	    	url: '<%=path%>/rfbase/fncprjpaysch/initGrid.do',
	    	method : 'get',
	        columns: [
	            { display: '状态', name: 'BETWNDAYS', width: 60 , align:'center', enabledSort:true,
	            	render: function (rowdata, rowindex, value, column) { 
		            		if(StringUtils.isEmpty(value)){
		                		value = "";
		                	}
		                	var imgpath = '';
		                	if(rowdata.BETWNDAYS>0 || rowdata.TOLAMT==0){//归集日大于当日 或者不存在未还流水 绿色
		                		imgpath = '<%=path%>/resource/lib/images/greenpoticon.png';
		                	}else if(rowdata.BETWNDAYS<=0 && rowdata.BETWNDAYSP>0){//归集日小于当日，且还款日大于当日 黄色
		                		imgpath = '<%=path%>/resource/lib/images/goldenpoticon.png';
		                	}else{//其他红色
		                		imgpath = '<%=path%>/resource/lib/images/redpoticon.png';
		                	}
		                	var g = '<img alt="" width="20px" height="20px" src="'+imgpath+'">';         
			                return g;
	            		}},
	    	    { display: '项目名称', name: 'PRJNM', width: 150, enabledSort:true },
	            { display: '金融机构', name: 'FUNDRASINSNM', width: 150, enabledSort:true },
	            { display: '机构缩写', name: 'INSABB', width: 150 , enabledSort:true},
	            { display: '机构类型', name: 'INSTYPENM', width: 150,enabledSort:true},
	            { display: '最近归集日', name: 'GTHRDT', width: 150 , render:renderDate, enabledSort:true},
	            { display: '还款日', name: 'PAYDT',width:150, render:renderDate1, enabledSort:true},
	            { display: '还款类别', name: 'REPYTP', width: 150 , enabledSort:true, 
	            	render: function (item){
                        if (parseInt(item.REPYTP) == 1) return '主动还款';
                        return '被动还款';
	            	}	
	            },
	            { display: '还款ID', name: 'PAYSCHID',width:0, hide:true},
	            { display: '项目ID', name: 'PROJID',width:0, hide:true},
	            { display: '还款状态', name: 'REPAYSTCD',width:0,hide:true},
	            { display: '未还款总计', name: 'TOLAMT',width:0,hide:true},
	            getGridOperColumnContent()
	        ],
	        pageSize:10,
	        width: '100%',
	        height:'100%',
	        rownumbers:true
	    });
	    grid = liger.get("ligergrid1");
	    grid.setHeight(200);	
	}
	
	//隐藏掉操作列
	function getGridOperColumnContent(){
		var data = {
	            display: '操作',
	            isSort: false,
	            width: 180,
	            align:'left',
	            render: function (rowdata, rowindex, value){
	        		var h="";
	        		if(rowdata.REPAYSTCD=='2'){
	        			h+='<a class="sq-button-hasicon" alt="详情" href="javascript:viewRepay(';
	                    h+="'"+rowdata.PROJID+"'";
	                    h+=")\"><i class=\"sqBtnIco_4\"></i>详情</a>"  
	        		}else{
	                	h+='<a class="sq-button-hasicon" alt="还款申请" href="javascript:startRepay(';
	                    h+="'"+rowdata.PAYSCHID+"'";
	                    h+=",'"+rowdata.PROJID+"'";
	                    h+=",'"+rowdata.REPAYSTCD+"'";
	                    h+=",'"+rowdata.BETWNDAYSP+"'";
	                    h+=",'ligergrid_bankacc'"
	                    h+=")\"><i class=\"sqBtnIco_4\"></i>还款申请</a>"  
	        		}
	                return h;
	            }
	    	 }
	    	return data;
	}
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	//格式化时间
	function renderDate1(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			date.setDate(date.getDate()-1);//还款日T-1日 
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
	function initInstLstForm(){
		$("#fncInsId").ligerComboBox({ 
		        url:'<%=path%>/rfbase/fncprjpaysch/initInstList.do',
		        ajaxType :'GET', 
		        valueField: 'id', textField: 'fundRasInsNm',
				columns: [
	                { header: '机构编号', name: 'id', width: 140 }, 
	                { header: '机构名称', name: 'fundRasInsNm', width: 120 },
	            ], 
	            width: 200,
	            selectBoxWidth: 480, 
	            selectBoxHeight: 240,
	            autocomplete: function (e){
	                 filter_autoComboboxData(e.key, this);
	                 e.show();
	             }
	        });
	}
	
  	function startRepay(payschid,pid,repaystcd,betwndays){
  		if(betwndays!=null && Number(betwndays)>15){
  			//alert("还款日15日内方可发起还款,当前距离还款日天数："+betwndays);
  			//return;
  		}
		var callback = function(){
			 grid.reload();
		}
		var timestamp=new Date().getTime();
		Add_navTab( 'tab_prj_pay_sch_start'+timestamp,'还款申请',
				'<%=path%>/rfbase/fncprjpaysch/toRepayPage.do?payschid='+payschid+'&pid='+pid+'&repaystcd='+repaystcd,callback);
  	}
  	function viewRepay(projid){
  		
  		var callback = function(){
			 
		}
  		var timestamp=new Date().getTime();
		Add_navTab( 'tab_prj_pay_sch_start'+timestamp,'还款详情',
				'<%=path%>/rfbase/fncprjpaysch/toRepayModifyPage.do?projid='+projid,callback);
  	}
</script>
</body>
</html>